package com.example.wendao.model.service;

import androidx.paging.DataSource;

import com.example.wendao.model.db.dao.NewsCommentDao;
import com.example.wendao.model.db.database.AppDatabase;
import com.example.wendao.model.entity.NewsComment;

public class NewsCommentService {
    private NewsCommentDao newsCommentDao;



    public NewsCommentService(){ newsCommentDao= AppDatabase.getDatabases().getNewsCommentDao(); }

    //插入评论
    /*
     * param:新闻评论
     * return:空
     * */
    public void insertForum(NewsComment... newsComments){ newsCommentDao.insertForum(newsComments);}

    //查询所有新闻评论
    /*
     * param:空
     * return:分页所有新闻评论列表的数据源工厂
     * */
    public DataSource.Factory<Integer, NewsComment> findByAllNewsComments(){
        return newsCommentDao.findAllNewsComments();
    }

    ///根据所属论坛或新闻查找评论
    /*
     * param:父新闻或父论坛id
     * return:该论坛或新闻下的分页所有评论列表的数据源工厂
     * */
    public DataSource.Factory<Integer, NewsComment> findAllNewsCommentsByFatherId(int fatherid,int newsorforum){
        return newsCommentDao.findAllNewsCommentsByFatherId(fatherid,newsorforum);
    }

    //根据所属父评论查找评论
    /*
     * param:父评论id
     * return:该评论下的分页所有回复列表的数据源工厂
     * */
    public DataSource.Factory<Integer, NewsComment> findAllNewsCommentsByFatherCommentId(int fathercommentid,int newsorforum){
        return newsCommentDao.findAllNewsCommentsByFatherCommentId(fathercommentid,newsorforum);
    }

    //更新新闻评论
    /*
     * param:评论
     * return:空
     * */
    public void updateNewsComments(NewsComment... newsComments){newsCommentDao.updateNewsComments(newsComments);}

    //删除新闻评论/*
    //    * param:评论
    //    * return:空
    //    * */
    public void deleteNewsComment(NewsComment... newsComments){ newsCommentDao.deleteNewsComment(newsComments);}



    //查找用户新闻下的所有评论
    public DataSource.Factory<Integer, NewsComment> findAllNewsCommentsBynewsids(String sql){
        return newsCommentDao.findAllNewsCommentsBynewsids(sql);}

    //查找用户论坛下的所有评论
    public DataSource.Factory<Integer, NewsComment> findAllForumsCommentsBynewsids(String sql){
        return newsCommentDao.findAllForumsCommentsBynewsids(sql);}


}
